export const getSetting=()=>{
  return new Promise((resolve,reject)=>{
    wx.getSetting({
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const getSystemInfo=()=>{
  return new Promise((resolve,reject)=>{
    wx.getSystemInfo({
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const login=()=>{
  return new Promise((resolve,reject)=>{
    wx.login({
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const getUserInfo=()=>{
  return new Promise((resolve,reject)=>{
    wx.getUserInfo({
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const getUserProfile = () => {
  // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
  return new Promise((resovle,reject) => {
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        resovle(res)
      }
    })
  })
}

export const getImageInfo=(path)=>{
  return new Promise((resolve,reject)=>{
    wx.getImageInfo({
      src: path,
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const canvasToTempFilePath=(params)=>{
  return new Promise((resolve,reject)=>{
    wx.canvasToTempFilePath({
      ...params,
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const saveImageToPhotoAlbum=(path)=>{
  return new Promise((resolve,reject)=>{
    wx.saveImageToPhotosAlbum({
      filePath:path,
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    });
  });
}

export const downloadFile=(path)=>{
  return new Promise((resolve,reject)=>{
    wx.downloadFile({
      url:path,
      success:(result)=>{
        resolve(result);
      },
      fail:(err)=>{
        reject(err);
      }
    })
  });
}